package cn.itcast.jobs.task;


import cn.itcast.jobs.pojo.JobInfo;
import cn.itcast.jobs.service.JobInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

@Component
public class SpringDataPipeline implements Pipeline {

    @Autowired
    private JobInfoService jobInfoService;
    @Override
    public void process(ResultItems resultItems, Task task) {
//        获取封装号的粉状对象

        JobInfo jobInfo =resultItems.get("jobInfo");

//        如果不为空则保存
        if (jobInfo!=null){
            this.jobInfoService.save(jobInfo);
        }
    }
}
